package Error;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA
 * User: HUAWEI
 * Date: 2023-05-25
 * Time: 23:38
 */

/*
* 程序先执行try中的代码
* 如果try中的代码出现异常，就会结束try中的代码，看和catch中的异常类型是否匹配
* 如果找到匹配的异常类型，就会执行catch中的代码
* 如果没有找到匹配的异常类型，就会将异常向上传递到上层调用者
* 无论是否找到匹配的异常类型，finally中的代码就会被执行到(在该方法结束之前执行)
* 如果上层调用者也没有处理的了异常，就继续向上传递
* 一直main方法也没有合适的代码处理异常，就会交给jvm来处理，此时程序就会异常终止
* */


class Person1 {
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}




public class Test {
        private String userName = "admin";
        private String passWord = "123456";

        public void loginInfo(String userName, String passWord) throws UserNameException{
            if (!this.userName.equals(userName)) {
                throw new UserNameException(userName+"用户名错误！");
                //System.out.println("用户名错误！");
                //return;
            }
            if (!this.passWord.equals(passWord)) {
                throw new PassWordException(passWord+"密码错误！");
                //System.out.println("密码错误！");
                //return;
            }
            System.out.println("登录成功");
        }

    public static void main(String[] args) {
        Test login = new Test();
        try {
            login.loginInfo("ad111","123456");
        }catch (UserNameException e) {
            e.printStackTrace();
        }
    }


    public static void main3(String[] args) {
        System.out.println("before");
        Scanner sc = new Scanner(System.in);
        try {
            int a = sc.nextInt();
            int ret = 10/a;
            System.out.println("ret的值是："+ret);
        }catch (ArithmeticException e) {
            System.out.println("我捕获到了：ArithmeticException这个异常！");
        }catch (NullPointerException e) {
            System.out.println("我捕获到了：NullPointerException异常！");
        }catch (InputMismatchException e){
            System.out.println("输入的参数有异常");
        }finally { // 此处的语句无论是否发生异常，都会被执行到
            sc.close();
            System.out.println("finally 执行了");
        }
        System.out.println("after");
    }
    public static void main2(String[] args){
        Person1 person = new Person1();
        try {
            Person1 person2 = (Person1) person.clone();
        }catch (CloneNotSupportedException e) {

        }
        System.out.println("1111111111asdfa");
    }

    public static void main1(String[] args) throws CloneNotSupportedException{
        Person1 person = new Person1();
        Person1 person2 = (Person1) person.clone();
        System.out.println("11111111");
    }

    
}
